package cn.ly.security.service.impl;

import cn.ly.security.dao.UserMapper;
import cn.ly.security.entity.DeviceUserArea;
import cn.ly.security.entity.Role;
import cn.ly.security.entity.User;
import cn.ly.security.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService  {
    @Autowired
    UserMapper userMapper;


    @Override
    public List<User> selectUserList(Integer currentPage, Integer size) {
        List<User> userList = userMapper.selectUserList((currentPage - 1) * size, size);
        return userList;
    }

    @Override
    public List<User> selectUserListById(Integer id, Integer currentPage, Integer size) {
        List<User> users = userMapper.selectUserListById(id, (currentPage - 1) * size, size);
        return users;
    }

    @Override
    public List<User> selectUserListByName(String uUsername, Integer currentPage, Integer size) {
        List<User> users = userMapper.selectUserListByName(uUsername, (currentPage - 1) * size, size);
        return  users;
    }

    @Override
    public Map<String, Object> login(String uUsername, String uPassword) {
        User login = userMapper.login(uUsername, uPassword);
        HashMap<String, Object> objectObjectHashMap=null;
        if (login!=null){
            String str = userMapper.selectPath(login.getUId());
            objectObjectHashMap = new HashMap<>();
            String[] split = str.split(",");
            for (String s : split) {
                int i = s.lastIndexOf(":");
                String substring = s.substring(i + 1);
                String substring1 = s.substring(0, i);
                objectObjectHashMap.put(substring1,substring);
            }
        }
        return objectObjectHashMap;
    }

    @Override
    public User registcheck(String uUsername) {
        User user=new User();
        user.setUUsername(uUsername);
        User registcheck = userMapper.registcheck(user);
        return registcheck;
    }
}
